<?php

	 require('../database/bd_connect.php');

//ALERTS		

//$wlan =	check_wlan($cpe);

//NOTICES


if (isset($_GET['opt'])){	
	$cpe = $_GET['opt'] ;
	
	
	//NOTICES:
	function check_wlan_mode($cpe){
		require('../database/bd_connect.php');
		//Wireless is operating in legacy mode if different from n return 1 if is enable 0 if disabled
		$sql = "SELECT COUNT(*) FROM cpe WHERE cpe_id=".$cpe." AND wlan_standard='n';";
		$result = $conn->query($sql);
		$row = mysqli_fetch_array($result);
		if ($row[0] != 1) {
			echo('<div class="" id="variance_alert" ><div class="alert alert-warning alert-dismissable" ><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><b>Notice! </b>Wireless is operating in legacy mode!</div></div>');		
		}
	}
	function check_wlan_channelmode($cpe){
		require('../database/bd_connect.php');
		//Wireless Channel manually set if different from 1
		$sql = "SELECT COUNT(*) FROM cpe WHERE cpe_id=".$cpe." AND wlan_channelmode='Auto';";
		$result = $conn->query($sql);
		$row = mysqli_fetch_array($result);
		if ($row[0] != 1) {
			echo('<div class="" id="variance_alert" ><div class="alert alert-warning alert-dismissable" ><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><b>Notice! </b>Wireless channel configured manually!</div></div>');		
		}
	}
	function check_wlan_advertisement($cpe){
		require('../database/bd_connect.php');
		//Wireless Advertisement is disabled if different from 1
		$sql = "SELECT COUNT(*) FROM cpe WHERE cpe_id=".$cpe." AND wlan_ssidadvert=1;";
		$result = $conn->query($sql);
		$row = mysqli_fetch_array($result);
		if ($row[0] != 1) {
			echo('<div class="" id="variance_alert" ><div class="alert alert-warning alert-dismissable" ><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><b>Notice! </b>Wireless advertisement is disabled!</div></div>');		
		}
	}
	function check_wlan_noise($cpe){
		require('../database/bd_connect.php');
		//Wireless is operating in legacy mode if different from n return 1 if is enable 0 if disabled
		$sql = "SELECT avg(abs(noise_hour.average)) AS noise FROM noise_hour inner join cpe on cpe.cpe_id = noise_hour.cpe_id WHERE noise_hour.cpe_id=".$cpe." AND noise_hour.time >= NOW() - INTERVAL 1 DAY and noise_hour.channel=cpe.wlan_channel";
		$result = $conn->query($sql);
		$row = mysqli_fetch_array($result);
		if ( $row[0] >= 7000 ) {
			echo('<div class="" id="variance_alert" ><div class="alert alert-warning alert-dismissable" ><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><b>Notice! </b>Wifi-channel with heavy occupation!</div></div>');		
		}
	}

check_wlan_mode($cpe);
check_wlan_channelmode($cpe);
check_wlan_advertisement($cpe);
check_wlan_noise($cpe);
}
?>
